﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EasyClassUI.entity;
using EasyClassUI.WebRequest;
using EasyClassUI.forms.group;

namespace EasyClassUI.forms.blog
{
    public partial class addCommentForm : Form
    {
        private Post post;
        public addCommentForm(Post post)
        {
            InitializeComponent();
            this.post = post;
            errMsg.Visible = false;
        }

        private void ConfirmButton_Click(object sender, EventArgs e) {
            if (commentText.Text == "") {
                errMsg.Visible = true;
                errMsg.Text = "Your comment is empty.";
            }
            // 按下评论确定按钮 记得设置一个正在编辑的评论ID的全局变量
            PostService postService = new PostService();
            string result = postService.CommentPost(post.PostID.ToString(), User.CurrentUser.Token, commentText.Text);
            if (result == "200") {
                blogDetailShow displayWindow = (blogDetailShow)this.Owner;
                displayWindow.addComment(commentText.Text);
                this.Close();
            }
            else {
                errMsg.Visible = true;
                errMsg.Text = "Something went wrong, please check your networks.";
            }
        }
    }
}
